package com.suitsoft.bdms.web.system;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;
import com.suitsoft.bdms.commos.TreeInfo;
import com.suitsoft.bdms.entity.system.STreeInfo;
import com.suitsoft.bdms.service.system.SystemInfoManager;

/**
 * 目录树管理.
 * 
 * @author Jack
 */
@Component
@SuppressWarnings("serial")
public class SystemTreeAction extends ActionSupport {
	@Autowired
	private TreeInfo treeInfo;

	private STreeInfo treeinfo;

	@Autowired
	private SystemInfoManager systemInfoManager;

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}

	public STreeInfo getSt() {
		return treeinfo;
	}

	public SystemInfoManager getSystemInfoManager() {
		return systemInfoManager;
	}

	public STreeInfo getTreeinfo() {
		return treeinfo;
	}

	public TreeInfo getTreeInfo() {
		return treeInfo;
	}

	public void search() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String id = request.getParameter("tid");
		treeinfo = systemInfoManager.findTree(new Long(id));
		String a = "" + treeinfo.getNodeid() + "," + treeinfo.getParentid() + "," + treeinfo.getCaption() + ","
				+ treeinfo.getNodeurl() + "," + treeinfo.getTarget() + "," + treeinfo.getTipinfo() + ","
				+ treeinfo.getIcon() + "";
		HttpServletResponse r = ServletActionContext.getResponse();
		System.out.println(a);
		PrintWriter out;
		try {
			out = r.getWriter();
			r.setCharacterEncoding("GBK");
			out.print(a);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void setSt(STreeInfo t) {
		this.treeinfo = t;
	}

	public void setSystemInfoManager(SystemInfoManager systemInfoManager) {
		this.systemInfoManager = systemInfoManager;
	}

	public void setTreeinfo(STreeInfo treeinfo) {
		this.treeinfo = treeinfo;
	}

	public void setTreeInfo(TreeInfo treeInfo) {
		this.treeInfo = treeInfo;
	}

	public String update() {
		HttpServletRequest request = ServletActionContext.getRequest();
		System.out.println(request.getParameter("treeinfo.nodeid"));
		systemInfoManager.updateTree(treeinfo);
		return SUCCESS;
	}
}
